package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ICopyrightService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.CopyrightCreateValidate;
import com.mdd.admin.validate.CopyrightUpdateValidate;
import com.mdd.admin.validate.CopyrightSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.CopyrightListedVo;
import com.mdd.admin.vo.CopyrightDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/copyright")
@Api(tags = "提案管理版权管理")
public class CopyrightController {

    @Resource
    ICopyrightService iCopyrightService;

    @GetMapping("/list")
    @ApiOperation(value="提案管理版权列表")
    public AjaxResult<PageResult<CopyrightListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated CopyrightSearchValidate searchValidate) {
        PageResult<CopyrightListedVo> list = iCopyrightService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="提案管理版权详情")
    public AjaxResult<CopyrightDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        CopyrightDetailVo detail = iCopyrightService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "提案管理版权新增")
    @PostMapping("/add")
    @ApiOperation(value="提案管理版权新增")
    public AjaxResult<Object> add(@Validated @RequestBody CopyrightCreateValidate createValidate) {
        iCopyrightService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "提案管理版权编辑")
    @PostMapping("/edit")
    @ApiOperation(value="提案管理版权编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody CopyrightUpdateValidate updateValidate) {
        iCopyrightService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "提案管理版权删除")
    @PostMapping("/del")
    @ApiOperation(value="提案管理版权删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iCopyrightService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
